#include <stdio.h>

int do_search(int nums[], int l, int r, int target)
{
    if (r < l)
        return -1;

    int mid  = l + (r-l)/2;
    if (nums[mid] == target)
        return mid;
    else if (nums[mid] > target)
        return do_search(nums, l, mid-1, target);
    else // if (nums[mid] < target)
        return do_search(nums, mid+1, r, target);
}


int main(void)
{
    printf("二分查找\n\n");
    int nums[] = {1,4};
    int target = 1;
    printf("find idx: %d\n", do_search(nums, 0, sizeof(nums)/sizeof(int), target));
    return 0;
}